<template>
	<view>
		<uni-forms ref="form" :modelValue="form" :label-width="80" style="background-color: #fff;">
			<uni-forms-item label="收件人" required name="toEmil">
				<uni-easyinput v-model="form.toEmil"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="抄送人" name="ccEmil">
				<uni-easyinput v-model="form.ccEmil"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="密送人" name="bccEmil">
				<uni-easyinput v-model="form.bccEmil"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="主题" name="title">
				<uni-easyinput v-model="form.title"></uni-easyinput>
			</uni-forms-item>
		</uni-forms>
		<view style="padding: 10rpx; height: 600rpx;">
			<view class="text-red text-sm">注释：邮件内容请在PC端编辑</view>
			<view v-html="form.text" style="padding: 10rpx;background-color: beige;"></view>
		</view>
	</view>
</template>

<script>
	import {
		getFormwork,
		updateFormwork
	} from "@/api/control/formwork";
	export default {
		data() {
			return {
				form: {
					id: 1,
					toEmil: '',
					ccEmil: '',
					bccEmil: '',
					title: '',
					text: '',
				},
			}
		},
		onShow() {
			const id = this.form.id
			getFormwork(id).then(response => {
				this.form = response.data;
			});
		},
		methods: {
			onNavigationBarButtonTap() {
				this.submitForm()
			},
			/** 提交按钮 */
			submitForm() {
				this.$refs.form.validate(['id'], (err, form) => {
					if (!err) {
						if (this.form.id != null) {
							updateFormwork(this.form).then(response => {
								this.$modal.msgSuccess("修改成功");
								this.open = false;
								this.getList();
							});
						} else {
							addFormwork(this.form).then(response => {
								this.$modal.msgSuccess("新增成功");
								this.open = false;
								this.getList();
							});
						}
					}
				});
			},
		},
	}
</script>

<style scoped>
page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
</style>